
#pragma once
#include "..\\..\\Miracl\\big.h"

class CBigRSA
{
public:
	CBigRSA();
	~CBigRSA();
	byte* decode(const byte *buffer, intptr_t bufLen, intptr_t &dataLen);
	byte* decode(LPCSTR buffer, intptr_t &dataLen);
protected:
	Big keyN, keyD;
	static byte* LPCSTRToData(LPCSTR buffer, intptr_t &dataLen);
	static bool LPCSTRToBig(LPCSTR buffer, Big&b);
#if defined(__ENCODE__)
public:
	bool genKey(int keyWidth);
	__forceinline LPCSTR getN() const{ return CBigRSA::BigToLPCSTR(keyN); }
	__forceinline LPCSTR getD() const{ return CBigRSA::BigToLPCSTR(keyD); }
	__forceinline  LPCSTR getE() const{ return CBigRSA::BigToLPCSTR(keyE); }
	byte* encode(const byte *buffer, intptr_t bufLen, intptr_t &dataLen);
	LPCSTR encode(const byte *buffer, intptr_t bufLen);
protected:
	Big keyE;
	Big strongp(int n, int seed1, int seed2);
	static LPCSTR DataToLPCSTR(byte *data, intptr_t dataLen);
	static LPCSTR BigToLPCSTR(const Big&b);
#endif
};
